<template>
    <el-container>
    <el-header style="text-align: left;flex-direction: row;display: flex;align-items: center; font-size: 12px">
      <el-button type="primary" @click="taskFormVisble = true">新建任务</el-button>

    </el-header>
    
    <el-main>
      <el-table :data="tableData" >
        <el-table-column  label="序号" width="100">
            <template slot-scope="scope">
            {{scope.$index+1}} 
          </template>
        </el-table-column>
        <el-table-column prop="create_user" label="创建人">
        </el-table-column>
        <el-table-column prop="created_at" label="创建时间">
        </el-table-column>
        <el-table-column prop="username" label="用户名">
        </el-table-column>
        <el-table-column prop="product_name" label="项目名称" >
        </el-table-column>
        <el-table-column  label="IMEI列表">
            <el-button type="text" size="small">IMEI列表</el-button>

        </el-table-column>
        <el-table-column prop="error" label="错误信息">
        </el-table-column>
        <el-table-column prop="remark" label="备注">
        </el-table-column>
      </el-table>
    </el-main>

     <el-dialog title="新建任务" :visible.sync="taskFormVisble">
          <el-form :model="taskForm" >
               <el-form-item label="uuid" :label-width="formLabelWidth">
                   <el-select v-model="taskForm.uuid" placeholder="请选择">
                    <el-option
                      v-for="item in selectFiled"
                      :key="item.uuid"
                      :label="item.uuid"
                      :value="item.uuid">
                    </el-option>
                  </el-select>
              </el-form-item>
              <el-form-item label="phone" :label-width="formLabelWidth">
              <el-input v-model="taskForm.phone" autocomplete="off"></el-input>
              </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="taskFormVisble = false">取 消</el-button>
          <el-button type="primary" @click="taskFormSubmit">确 定</el-button>
      </div>
    </el-dialog>



    </el-container>
</template>

<script>
    import {Axios} from "../../../static/util";
    export default {
        name:"dm",
        methods: {
           taskFormSubmit(){
              let self = this;
              Axios(
                'post',
                'http://127.0.0.1:5000/device_assign',
                self.taskForm,
                (res)=>{
                if (res.data.code != "200"){
                    this.$message.warning('错误:'+res.data.msg);
                    
                }else{
                    this.$message.info(res.data.msg);
                    this.$router.go(0);
                }
                  
              });
           }
        },
         data(){

            return {
                tableData: [],
                taskFormVisble:false,
                taskForm:{
                  uuid:'',
                  phone:''
                },
                formLabelWidth:'120px',
                selectFiled:[]

            };
        },
        created(){
          let self = this;
            Axios(
              'get',
              'http://127.0.0.1:5000/device_assign',
              {},
              (res)=>{
              if (res.data.code != "200"){
                  this.$message.warning('错误:'+res.data.msg);
                  
              }else{
                this.tableData = res.data.data;
                
              }
                
            });
            Axios(
              'get',
              'http://127.0.0.1:5000//get_device_col_info',
              {data:'uuid'},
              (res)=>{
              if (res.data.code != "200"){
                  this.$message.warning('错误:'+res.data.msg);
                  
              }else{
                this.selectFiled = res.data.data;
                console.log(res);
              }
                
            },{data:'uuid'});
        }


    }
</script>

<style>
</style>
